package com.p2p.front.dal.dao;


import java.util.List;
import java.util.Map;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import com.p2p.base.dao.BaseMapper;
import com.p2p.base.model.BaseUser;
import com.p2p.front.dal.model.User;

public interface UserDao extends BaseMapper {
	
	@Insert("INSERT INTO p2p_user(uid,umobile,uemail,uname,password,addtime)values(#{uid},#{umobile},#{uemail},#{uname},#{password},now())")
	public void save(User user);

	@Select("select * from  p2p_user where uid =#{id}")
	public User findById(String id);
	
	@Update("update p2p_user set password = #{password},uptime=now() where uid = #{uid}")
	public int updateByPwd(User user);
	
	public void update(User user);
	
	@Update("UPDATE p2p_user SET accountNo=#{accountNo} WHERE uid = #{uid}")
	public int updateAccountNo(User user);

	User checkMobileOrEmailExist(@Param("mobile") String mobile,@Param("email")String email);
	
	/**
	 * 校验用户是否存在
	 * @author hongbo
	 * @param name
	 * @return
	 */
	User checkUserNameExist(String name);
	
	/**
	 * 校验用户身份ID是否存在
	 * @author hongbo
	 * @param idcard
	 * @return
	 */
	User checkUserIdcardExist(String idcard);
	
	/**
	 * 修改手机
	 * @author hongbo
	 * @param user
	 */
	void updateModifyMobile(User user);
	
	@Select("select * from p2p_user where uname = #{uname}")
	User findByUname(String uname);
	
	@Select("select * from p2p_user where umobile = #{mobilephone}")
	public User findByPhone(String mobilephone);

	@Update("update p2p_user set realname =#{real_name},idcard =#{card_id} where uid=#{uid}")
	public void addCardInfo(@Param(value="real_name")String real_name, 
			@Param(value="card_id")String card_id, @Param(value="uid")String uid);
	
	@Select("select * from p2p_user where uemail = #{email}")
	public User findByEmail(String email);

	@Update("update p2p_user set uemail = #{uemail} where uid = #{uid}")
	public void updateEmail(User user);

	@Select("select * from p2p_user where uid = #{uid}")
	public Map<String, Object> get(Long uid);
	
	public List<Map<String, Object>> batchList(List<Map<String, Object>> list);
	
	@Select("select * from p2p_user where umobile like #{search}\"%\" or uid like #{search}\"%\" or uname like #{search}\"%\" or realname like  #{search}\"%\"")
	public List<User> search(String search);

	@Select("select * from p2p_user where idcard = #{idcard}")
	public Map<String, Object> findCard(String idcard);
	
	
	public List<User> searchUserByIdList(List<String> idList);

}
